﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using QS.Logic.Objects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using QS.Input;

namespace QS.Game.Camera
{
    class QCameraManager
    {
        private const int FIRST_PERSON_CAMERA_INDEX = 0;
        private const int FREE_CAMERA_INDEX = 1;
        private const int THIRD_PERSON_CAMERA_INDEX = 2;
        private const int SMOOTH_THIRD_PERSON_CAMERA_INDEX = 3;

        private Hashtable cameraTable;
        private int currentCameraIndex = SMOOTH_THIRD_PERSON_CAMERA_INDEX;

        public QCameraManager()
        {
            this.cameraTable = new Hashtable();
        }

        public void Load(GraphicsDevice graphicsDevice, ContentManager contentManager, QSpaceShip spaceShip)
        {
            this.cameraTable.Add(FIRST_PERSON_CAMERA_INDEX, new QFirstPersonCamera(graphicsDevice, spaceShip));
            this.cameraTable.Add(FREE_CAMERA_INDEX, new QFreeCamera(graphicsDevice));
            this.cameraTable.Add(THIRD_PERSON_CAMERA_INDEX, new QStaticThirdPersonCamera(graphicsDevice, spaceShip));
            this.cameraTable.Add(SMOOTH_THIRD_PERSON_CAMERA_INDEX, new QSmoothThirdPersonCamera(graphicsDevice, spaceShip));
        }

        public virtual void Update(GameTime time)
        {
            List<Keys> keys = QKeyboardOperations.KeysDown;
            if (keys.Contains(Keys.F1))
            {
                this.currentCameraIndex = FIRST_PERSON_CAMERA_INDEX;
                keys.Remove(Keys.F1);
            }

            if (keys.Contains(Keys.F2))
            {
                this.currentCameraIndex = FREE_CAMERA_INDEX;
                keys.Remove(Keys.F2);
            }

            if (keys.Contains(Keys.F3))
            {
                this.currentCameraIndex = THIRD_PERSON_CAMERA_INDEX;
                keys.Remove(Keys.F3);
            }

            if (keys.Contains(Keys.F4))
            {
                this.currentCameraIndex = SMOOTH_THIRD_PERSON_CAMERA_INDEX;
                keys.Remove(Keys.F4);
            }


            this.Camera.Update(time);
        }

        public QCamera Camera
        {
            get
            {
                return this.cameraTable[this.currentCameraIndex] as QCamera;
            }
        }
    }
}
